<template>
	<view class="main">
		<uni-nav-bar title="工单管理" backgroundColor="#63a4f0" color="#222C33" statusBar="true" @clickLeft="back()"
			left-icon="arrowleft">
		</uni-nav-bar>
		<scroll-view class="scrollView" scroll-y="true" :style="{ height: 'calc(100vh - 44px)' }"
			@scrolltolower="handleScrolltolowerone()">
			<view style="text-align: center;font-size: 30rpx;font-weight: bold;">工单列表</view>
			<view class="search-box">
				<view class="search-item">
					<image class="left-img" src="@/static/order/gongdan.png" mode="heightFix" />
					<uni-easyinput :inputBorder="false" v-model="searchForm.reportNoLike"
						placeholder="输入工单号"></uni-easyinput>
					<button class="searchbutton" @click="serviceChange()">
						<text>搜索</text>
					</button>
				</view>
			</view>
			<OrderItem @resetList="queryPageList" @delItem="delItem" :dataList="dataList"></OrderItem>
			<view v-if="!dataList.length">
				<u-empty mode="message" icon="http://cdn.uviewui.com/uview/empty/message.png">
				</u-empty>
			</view>
			<view style="height: 30vh;"></view>
		</scroll-view>
		<!-- <bottomBar ref="bottomBar"></bottomBar> -->
		<view class="submit addEditBtn" @click="handleAdd">+新建工单</view>
	</view>
</template>

<script>
import bottomBar from "@/components/socialized-bottomtabar/home-bottomtabar"
import workOrderApi from '@/api/socialized-servce/person-message/work-order.js'
import OrderItem from "./components/order-item.vue"
export default {
	components: {
		bottomBar,
		OrderItem
	},
	data() {
		return {
			page: 1,
			size: 10,
			total: 0,
			totalPages: 0,
			dataList: [],
			searchForm: {},
			batchList: [],
			modalshow: false,
			modalTilte: '',
			serviceList: [],
			reportExecuteObj: {
				executeType: '',  //工单类型
				executeNo: '',  //所属项目编号
				projectNo: '',  //所属项目编号
				projectName: '',  //所属项目名称
				organizationNo: '',  //服务方编号
				organizationName: '',  //服务方名称
				providerNo: '',  //运营方编号
				providerName: '',  //运营方名称 
				memberNo: '',  //终端用户编号
				memberName: '',  //终端用户名称
				quantity: 0,//总面积
				executeAmount: 0,//总价
				unit: '', //面积单位
				price: 0
			}
		}
	},
	onLoad(v) {
		this.reportExecuteId = v ? v.reportExecuteId : ''
		uni.setStorageSync('reportExecuteId', this.reportExecuteId)
		this.executeNo = '';
		this.searchForm = {
			memberNo: '',
			projectNo: '',
			settlementNo: ''
		}
		this.initData();
	},
	mounted() { },
	methods: {
		//跳转订单是需要查询订单的基本信息
		async initData() {
			if (this.reportExecuteId) {
				// let { data } = await workOrderApi.queryReportExecuteById(this.reportExecuteId);
				let data = uni.getStorageSync('workOrderInfo') ? JSON.parse(uni.getStorageSync('workOrderInfo')) : {};
				for (let key in data) {
					if (key in this.reportExecuteObj) {
						this.reportExecuteObj[key] = data[key]
					}
				}
				if (this.reportExecuteObj.executeNo) {
					this.executeNo = this.reportExecuteObj.executeNo;
					uni.setStorageSync('reportExecuteObj', JSON.stringify(this.reportExecuteObj));
					console.log('getStorageSync:', uni.getStorageSync('reportExecuteObj'))
					this.queryPageList()
				} else {
					uni.showToast({
						title: '为获取到执行单',
						icon: 'error'
					})
				}
			} else {
				uni.showToast({
					title: '为获取到执行单',
					icon: 'error'
				})

			}
		},
		//添加
		handleAdd() {
			let url = '/pages/socialized-service/work-order/delivery-add-edit'
			this.$togo(url, {
				reportType: this.reportExecuteObj.executeType,
				addEditFlag: 'add'
			})
		},
		processing(item, params) {
			console.log(item, params);
			this.modalTilte = params.title
			this.modalshow = params.modalshow
			this.itemForm = JSON.parse(JSON.stringify(item))
		},
		serviceChange() {
			this.page = 1
			this.queryPageList()
		},
		//重置
		reset() {
			this.params = {}
			this.searchForm = {}
			this.page = 1
			this.queryPageList()
		},
		delItem(id) {
			console.log(id)
			this.dataList = this.dataList.filter(item => { return item.id !== id })
		},
		async queryPageList() {
			if (this.reportExecuteId && this.executeNo) {
				let params = {
					page: this.page,
					size: this.size,
					condition: {
						...this.searchForm,
						executeNo: this.executeNo,
					}
				}
				let res = await workOrderApi.queryPageByCondition(params)
				if (res.code === 200) {
					this.total = res.data.totalElements
					this.totalPages = res.data.totalPages
					let newList = res.data.content
					if (this.page === 1) {
						this.dataList = newList
					} else {
						this.dataList = [...this.dataList, ...newList]
					}
				}
			} else {
				uni.showToast({
					title: '为获取到执行单',
					icon: 'error'
				})
			}

		},
		handleScrolltolowerone() {
			if (this.loading) return;
			console.log('触底', this.page, this.totalPages);
			if (this.page <= this.totalPages && this.page * 10 < this.total) {
				this.page++
				this.queryPageList()
			}
		},

		//返回上一步
		back() {
			uni.navigateBack({
				delta: 1,
			});
		},
	}

}
</script>

<style lang="scss" scoped>
.scrollView {
	// padding-top: 20rpx;
	padding: 20rpx;
	box-sizing: border-box;

	.content {
		width: 100%;
		color: #000;

		.item {
			position: relative;
			padding: 0 40rpx;
			font-size: 28rpx;
			margin-bottom: 20rpx;

			.dot {
				position: absolute;
				top: 60rpx;
				right: 52rpx;
				width: 16rpx;
				height: 16rpx;
				border-radius: 50%;
				background-color: red;
				z-index: 999;
			}

			.img {
				position: absolute;
				top: 66rpx;
				right: 60rpx;
				width: 34rpx;
			}

			.title {
				padding-bottom: 10rpx;
				border-bottom: 2rpx solid #c7c7c9;
				color: #91743E;
			}

			.brief {
				.brief-item {
					width: 100%;
				}
			}

			.sendTime {
				width: 100%;
				text-align: center;
				margin-bottom: 10rpx;
				color: #c7c7c9;
			}

			.container {
				padding: 22rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.05);
				border-radius: 10rpx 10rpx 10rpx 10rpx;

				.title {
					display: flex;
					font-weight: 700;
					overflow: hidden;
					font-size: 32rpx;
				}

				.brief {
					margin-top: 20rpx;
				}

				.times {
					margin-top: 26rpx;
					font-size: 28rpx;
					color: #606060;
				}
			}
		}

	}
}

.noData {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translateX(-50%) translateY(-50%);
	width: 100%;

	.img {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;

		image {
			width: 166rpx;
			height: 153rpx;
		}

		.tex {
			font-size: 32rpx;
			font-family: Source Han Sans CN-Regular, Source Han Sans CN;
			font-weight: 400;
			color: #525252;
		}
	}

}

.search-box {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-around;

	.search-item {
		width: 90vw;
		height: 12vw;
		box-sizing: border-box;
		margin: 2vw auto;
		padding: 3vw;
		border-radius: 7vw;
		display: flex;
		justify-content: space-around;
		align-items: center;
		box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.09);
		background: #ffffff;

		.left-img {
			width: 6vw;
			height: 7vw;

		}
	}

	.searchbutton {
		font-size: 28rpx;
		font-family: Source Han Sans CN-Regular, Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 64rpx;
		width: 120rpx;
		height: 58rpx;
		opacity: 1;
		border-radius: 30rpx;
		background: linear-gradient(270deg, rgba(136, 172, 255, 1) 0%, rgba(33, 101, 255, 1) 100%);


	}
}

.addEditBtn {
	position: fixed;
	bottom: 10vh;
	left: 50%;
	transform: translateX(-50%);
	width: 50vw;
	height: 4vh;
	background: linear-gradient(270deg, #88ACFF 0%, #2165FF 100%);
	box-shadow: 0px 0px 5px 1px rgba(0, 0, 0, 0.29);
	border-radius: 3vh;
	text-align: center;
	line-height: 4vh;
	font-size: 30rpx;
	color: #ffffff;
}
</style>